﻿using AutoStar.Common;
using GalaSoft.MvvmLight.CommandWpf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace AutoStar.ViewModel
{
    public class WindowOtherVM : BaseViewModel
    {
        public WindowOtherVM()
        {
            GoMachineOrigin = new RelayCommand(GoMachineOriginExecute);
            GoPrintOrigin = new RelayCommand(GoPrintOriginExecute);
            GoSolidifyOrigin = new RelayCommand(GoSolidifyOriginExecute);
            SwitchFixLightCommand = new RelayCommand(SwitchFixLightExecute);
            GoZCommand = new RelayCommand(GoZExecute);
        }

        private void GoZExecute()
        {
            Global.printer.ZToZero();
        }

        /// <summary>
        /// 回到机器原点
        /// </summary>
        private void GoMachineOriginExecute()
        {
            Global.printer.XYToZero();
        }
        /// <summary>
        /// 回到打印原点
        /// </summary>
        private void GoPrintOriginExecute()
        {
            if (Global.printProject.printLayers.Count == 0)
            {
                return;
            }
            Point3D point = Global.printProject.printLayers[Global.printer.layerIndex].points[0];
            //int channel = Global.printProject.printLayers[Global.printer.layerIndex].channel;
            Global.printer.moveToRelative(point.X, point.Y, point.Z, Global.printProject.printLayers[Global.printer.layerIndex].channel);
        }
        /// <summary>
        /// 回到固化原点
        /// </summary>
        private void GoSolidifyOriginExecute()
        {
            if (Global.printProject.printLayers.Count == 0)
            {
                return;
            }
            Global.printer.moveToSolidifyZero();
        }
        /// <summary>
        /// 切换固化灯
        /// </summary>
        private void SwitchFixLightExecute()
        {
            if (solodfyLight)
            {
                Global.printer.SendGCode("M251");
            }
            else
            {
                Global.printer.SendGCode("M250");
            }
            solodfyLight = !solodfyLight;
        }
        bool solodfyLight = false;
        public ICommand GoMachineOrigin { get; private set; }
        public ICommand GoPrintOrigin { get; private set; }
        public ICommand GoSolidifyOrigin { get; private set; }
        public ICommand GoZCommand { get; private set; }
        public ICommand SwitchFixLightCommand { get; private set; }
    }
}
